<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">

    <link rel="stylesheet" href="../static/css/main.css" media="all">
    <script type="text/javascript" src="../static/lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../static/css/bootstrap.css">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>物业管理</cite></a>
              <a><cite>房屋出租管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">

    <div class="layui-form-item">

        <div class="layui-input-inline">
            <input type="text" name="houseId"  placeholder="请输入房屋编号"  class="layui-input"/>
            <button class="layui-btn" id="searchArea" name="搜索" onclick="search()">搜索</button>
        </div>

    </div>
    <xblock>

        <button class="layui-btn" onclick="admin_add('添加','house_add','1000','600')"><i class="layui-icon">&#xe608;</i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge"><input th:value="${session.pagebean.getPageNums()}"></span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" name="" value="">
            </th>
            <th>房屋的楼门号</th>
            <th>描述信息</th>
            <th>租赁价格</th>
            <th>租赁状态</th>
            <th>联系方式</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="x-img">
        <tr>
            <th>1</th>
            <td class="td-manage">
                <button id="editBtn" value="1" title="编辑" href="javascript:;" onclick="edit()"
                        class="ml-5" style="text-decoration:none">
                    <i class="layui-icon">&#xe642;</i>
                </button>
                <button title="删除" href="javascript:;" onclick="admin_del(this)"
                        style="text-decoration:none">
                    <i class="layui-icon">&#xe640;</i>
                </button>
            </td>
        </tr>

<!--        <tr th:each="ob:${session.houses}">-->
<!--            <td>-->
<!--                <input type="checkbox" value="1" name="">-->
<!--            </td>-->
<!--            <td id = "rentId" th:text="${ob.getRenteId()}">  </td>-->
<!--            <td th:text="${ob.getMsg()}"> </td>-->
<!--            <td th:text="${ob.getPrice()}"> </td>-->
<!--            <td th:text="${ob.getState()}"> </td>-->
<!--            <td th:text="${ob.getTelphone()}"> </td>-->
<!--            <td class="td-manage">-->
<!--                <button id="editBtn" th:value="${ob.getId()}" title="编辑" href="javascript:;" onclick="edit()"-->
<!--                   class="ml-5" style="text-decoration:none">-->
<!--                    <i class="layui-icon">&#xe642;</i>-->
<!--                </button>-->
<!--                <button title="删除" href="javascript:;" onclick="admin_del(this)"-->
<!--                   style="text-decoration:none">-->
<!--                    <i class="layui-icon">&#xe640;</i>-->
<!--                </button>-->
<!--            </td>-->
<!--        </tr>-->
        </tbody>
    </table>
    <div id="page">
        <tr>
            <td><a th:href="@{/house/getAll(pageSize=2,pageNum=1)}">首页</a></td>
            <td><a th:href="@{/house/getAll(pageSize=2,pageNum=${session.pagebean.getLastPage()})}" >上一页</a></td>
            <td><a th:href="@{/house/getAll(pageSize=2,pageNum=${session.pagebean.getNextPage()})}">下一页</a></td>
            <td><a th:href="@{/house/getAll(pageSize=2,pageNum=${session.pagebean.getMaxPgaeTotal()})}">尾页</a></td>
        </tr>
    </div>
</div>
<script src="../static/lib/layui/layui.js" charset="utf-8"></script>
<script src="../static/js/x-layui.js" charset="utf-8"></script>
<script>
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        okLoading.close($);

        layer.ready(function(){ //为了layer.ext.js加载完毕再执行
            layer.photos({
                photos: '#x-img'

            });
        });

    });
    function search(){
        layer.msg("okokko")
        var  textContent = $("input[name='houseId']").val()
        layer.msg(textContent)
        $.ajax({
            type: "GET",
            url: "/house/getById",
            data: {
                houseId:textContent
            },
            success:function (data) {
                alert("成功！")
            }
        })
    }



    /*添加*/
    function admin_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }

    function edit() {
        var id = document.getElementById('editBtn').value;
        house_edit('编辑','house_add',id,'1000','600')
    }

    //编辑
    function house_edit (title,url,id,w,h) {
        url = url+"?houseId="+id;
        x_admin_show(title,url,w,h);
    }
    /*删除*/
    function admin_del(obj){
        layer.confirm('确认要删除吗？',{icon:3,title:'提示信息'},function(){
            var id = document.getElementById('editBtn').value;
            $.ajax({
                type:"post",
                url:"/house/deleteById",
                data:{renteId:id},
                dataType:"json",
                success:function(data){
                    //console.log(data);
                    if(data.result=="SUCCESS"){
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg(data.info,{icon:6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    } else{
                        layer.msg(data.info,{icon:5,time:1000});return false;
                    }
                }
            });
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }
</script>

</body>
</html>